package org.grow.mpgo.service;

import org.grow.mpgo.dao.StudentScoreDao;
import org.grow.mpgo.entity.StudentScore;
import org.grow.mpgo.exception.TuesdayException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * @Author: xwg
 * @CreateDate: 21-7-13
 */

@Service
public class DealBillService {
    @Autowired
    private StudentScoreDao studentScoreDao;


    @Transactional()
    public boolean txDeal(StudentScore consumer, StudentScore supplier) {
        int i = studentScoreDao.updateById(consumer);
        if (i!=1){
            throw new TuesdayException("消费者乐观锁异常，系统繁忙，请过一分钟重新尝试");
        }
//        if (1 == 1) throw new RuntimeException("模拟断电了");
        int j = studentScoreDao.updateById(supplier);
        if (j!=1){
            throw new TuesdayException("提供者乐观锁异常，系统繁忙，请过一分钟重新尝试");
        }
        return true;
    }
}
